/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.observer;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author martin
 */
public class IntervalTrigger implements Runnable{
  private final long _interval;
  private final Trigger<Long> _callback;
  
  public IntervalTrigger(final long interval, final Trigger<Long> callback){
    _interval=interval;
    _callback=callback;
  }

  @Override
  public void run() {
    while (!Thread.currentThread().isInterrupted()){
      try {
        Thread.sleep(_interval);
        _callback.poke(System.nanoTime());
      } catch (InterruptedException ex) {
        Logger.getLogger(IntervalTrigger.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
  
}
